package com.vint.mi;


/**
 * 1. easy
 * 2. done
 * 旋转数列的中间值
 */
public class Mi5 {
    public static String solution(String line){
       String[] src = line.split(",");
       int len = src.length;
       if(len==1)return src[0];
       int[] a = new int[len];
       for(int i=0;i<len;i++)a[i]=Integer.parseInt(src[i]);
       int pre = a[0];
       int start = 0;
       int i = 0;
       for(i=1;i<len;i++) {
	       if (a[i] < pre) {
		       break;
	       } else {
		       pre = a[i];
	       }
       }
        int mid = (int)Math.ceil(len/2);
       	if(i>=len){
       	    return src[mid];
        }else{
       		return src[(i+mid)%len];
        }
    }

    public static void main(String[] args) {
        String ex1 = "4,5,6,7,8,9,10,0,1,2,3";
	    String ex2 = "4";
	    String ex3 = "4,7,8";
        System.out.println(solution(ex1));
	    System.out.println(solution(ex2));
	    System.out.println(solution(ex3));
    }
}
